# -*- coding: utf-8 -*-
import re


def res200(msg,data=None,addition=None):
    """用于查询"""
    if data == None:
        response = {"code": 200, "msg": msg}
    elif data != None and addition != None:
        response = {"code": 200, "msg": msg, 'data': data, "addition": addition}
    else:
        response = {"code": 200, "msg": msg, 'data': data}
    return response

def res201(msg,data=None,addition=None):
    """用于创建与修改成功"""
    if data == None:
        response = {"code":201,"msg":msg,'data':[]}
    elif data !=None and addition !=None:
        response = {"code": 201, "msg": msg, 'data': data,"addition":addition}
    else:
        response = {"code": 201, "msg": msg, 'data': data}
    return response

def res204(msg):
    """用于删除成功"""
    response = {"code": 204, "msg": msg}
    return response

def res400(msg):
    """产生异常"""
    response = {"code": 400, "msg": msg}
    return response

def name_re(name):
    name_pattern = re.compile(r'^[\u4e00-\u9fa5]{2,}$')
    if name_pattern.match(name):
        return True
    else:
        return False

def phone_re(phone):
    pattern = r"^1[3-9]\d{9}$"
    return re.match(pattern, phone) is not None
